#include "IAStateExplore.h"


#include <list>
#include "Ogre.h"

#include "GameManager.h"

#include "Maths.h"

#include "OgreFrameWork.h"

#include "IAStateBring.h"


IAStateExplore::IAStateExplore()
{
    //ctor
    m_distance=5;

}

IAStateExplore::~IAStateExplore()
{
    //dtor
}


/** @brief update
  *
  * @todo: document this function
  */
void IAStateExplore::update(double timeSinceLastFrame)
{
   // OgreFramework::getSingletonPtr()->m_pLog->logMessage("IA EXplore find new destination : destination" + Ogre::StringConverter::toString(m_destination));
   // OgreFramework::getSingletonPtr()->m_pLog->logMessage("IA EXplore find new destination : position " + Ogre::StringConverter::toString(m_parentCreature->getPosition()));
/*    if (m_parentCreature->getPosition().distance(m_destination)<0.1)
    {
        searchNewDestination();
    }

std::list<ItemObject*> items = GameManager::getInstance()->getObjectMgrPtr()->getItemsNear(m_parentCreature->getPosition(),0.2);
    if (!items.empty())
    {
        IAState* bringState = ((IA*) m_pParent)->createState(IA::STA_BRING);
        bringState->setParentCreature(m_parentCreature);
        bringState->getTarget()->setTarget((ItemObject*)items.back());

        changeState(bringState);
    }
*/
}

/** @brief resume
  *
  * @todo: document this function
  */
void IAStateExplore::resume()
{

}

/** @brief pause
  *
  * @todo: document this function
  */
bool IAStateExplore::pause()
{

}

/** @brief exit
  *
  * @todo: document this function
  */
void IAStateExplore::exit()
{

}

/** @brief enter
  *
  * @todo: document this function
  */
void IAStateExplore::enter()
{

searchNewDestination();



}

/** @brief searchNewDestination
  *
  * @todo: document this function
  */
void IAStateExplore::searchNewDestination()
{
/*    Ogre::Vector2 p = m_parentCreature->getPosition()+Ogre::Vector2(randInt(-m_distance,m_distance),randInt(-m_distance,m_distance));



    LevelBlock* b = GameManager::getInstance()->getLevelMgrPtr()->getBlockPtrAt(p);
    if (b!=0 && b->isCrossable())
    {
        m_destination=p;
        GameManager::getInstance()->getObjectMgrPtr()->giveOrderMovableToGoTo(m_parentCreature, p);
  //  OgreFramework::getSingletonPtr()->m_pLog->logMessage("IA EXplore find new destination : destination" + Ogre::StringConverter::toString(m_destination));
   // OgreFramework::getSingletonPtr()->m_pLog->logMessage("IA EXplore find new destination : position " + Ogre::StringConverter::toString(m_parentCreature->getPosition()));
    }
    else
    {
        m_destination = m_parentCreature->getPosition();
    }

*/

}

